var app = getApp()
var pageoffset
var pagenum

Page({
  data: {
    details: []
  },
  onLoad: function (options) {
    app.getUserInfo().then(res => {
      this.setData({
        balance: res.BALANCE
      })
    })
    pageoffset = 1
    pagenum = 20
    app.showLoading()
    this.loadDetail(pageoffset)
  },
  onReachBottom: function () {
    pageoffset++
    this.loadDetail(pageoffset)
  },
  updatePwd: function () {
    wx.navigateTo({
      url: '../password/password?target=update'
    })
  },
  rechargeMoney: function () {
    wx.redirectTo({
      url: '../balance',
    })
  },
  loadDetail: function (offset) {
    var url = '/yuanmai_we/user/userinfo/recharge/' + offset + '/' + pagenum
    app.get(url).then(res => {
      app.hideLoading()
      if (res.info.length <= 0) {
        pageoffset--
        return
      }
      var details = []
      if (pageoffset > 1) {
        details = this.data.details
      }
      for (var i = 0; i < res.info.length; i++) {
        res.info[i].type = parseInt(res.info[i].num) > 0 ? '1' : '-1'
        details.push(res.info[i])
      }
      this.setData({
        details: details
      })
    })
  }
})
